<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>like yuque</title>

  <link href="https://cdn.bootcdn.net/ajax/libs/normalize/8.0.1/normalize.min.css" rel="stylesheet">
  <link href="../dist/css/style.css" rel="stylesheet">
  <style>
    html,
    body {
      background-color: #fff;
      height: 100%;
      overflow: hidden;
      color: #333;
    }

    #top-container {
      border-bottom: 1px solid #e8e8e8;
      padding-left: 50px;
    }

    #editor-toolbar {
      width: 1300px;
      background-color: #FCFCFC;
      margin: 0 auto;
    }

    #content {
      height: calc(100% - 40px);
      background-color: rgb(245, 245, 245);
      overflow-y: auto;
      position: relative;
    }

    #editor-container {
      width: 850px;
      margin: 30px auto 150px auto;
      background-color: #fff;
      padding: 20px 50px 50px 50px;
      border: 1px solid #e8e8e8;
      box-shadow: 0 2px 10px rgb(0 0 0 / 12%);
    }

    #title-container {
      padding: 20px 0;
      border-bottom: 1px solid #e8e8e8;
    }

    #title-container input {
      font-size: 30px;
      border: 0;
      outline: none;
      width: 100%;
      line-height: 1;
    }

    #editor-text-area {
      min-height: 900px;
      margin-top: 20px;
    }
  </style>

</head>

<body>
  <div id="top-container">
    <p>
      <svg width="16" height="16" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg">
        <path
          d="M648.533333 85.333333L853.333333 290.133333V938.666667H170.666667V85.333333h477.866666m34.133334-85.333333H85.333333v1024h853.333334V256l-256-256z">
        </path>
        <path d="M256 341.333333h512v85.333334H256zM256 512h512v85.333333H256zM256 682.666667h512v85.333333H256z">
        </path>
      </svg>
      文章标题信息
    </p>
  </div>
  <div style="border-bottom: 1px solid #e8e8e8;">
    <div id="editor-toolbar"></div>
  </div>
  <div id="content">
    <div id="editor-container">
      <div id="title-container">
        <input value="请输入标题">
      </div>
      <div id="editor-text-area"></div>
    </div>
  </div>

  <script src="js/init-content.js"></script>
  <script src="../dist/index.js"></script>
  <script>
    const E = window.wangEditor

    const editorConfig = { MENU_CONF: {} }
    editorConfig.placeholder = '请输入内容'
    editorConfig.scroll = false // 禁止编辑器滚动
    editorConfig.MENU_CONF['uploadImage'] = {
      server: 'http://106.12.198.214:3000/api/upload-img', // 上传图片地址
      fieldName: 'like-yuque-fileName'
    }
    editorConfig.onChange = (editor) => {
      // console.log('content', editor.children)
    }

    // 先创建 editor
    const editor = E.createEditor({
      selector: '#editor-text-area',
      content: window.content1,
      config: editorConfig
    })

    // 创建 toolbar
    const toolbar = E.createToolbar({
      editor,
      selector: '#editor-toolbar',
      config: {
        excludeKeys: 'fullScreen',
      }
    })

    // 点击空白处 focus 编辑器
    document.getElementById('editor-text-area').addEventListener('click', e => {
      if (e.target.id === 'editor-text-area') {
        editor.blur()
        editor.focus(true) // focus 到末尾
      }
    })
  </script>
</body>

</html>